package com.groupnections.client.Entities;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.groupnections.client.GlobalVariables;
import com.groupnections.shared.Entity;

public class EntityPage extends AbsolutePanel {

	public static VerticalPanel vpEntitiesRelated = new VerticalPanel();

	public static VerticalPanel vpMiddleContent = new VerticalPanel();

	public EntityPage(Entity entity) {

		this.setSize("800px", "600px");

		Image image = new Image(GlobalVariables.IMAGE_FOLDER
				+ entity.getEntityID() + ".jpg");
		this.add(image, 10, 17);
		image.setWidth("100px");

		HTML lblAllineWatkins = new HTML("<font size=3><b>"
				+ entity.getEntityName() + "</b></font>");
		this.add(lblAllineWatkins, 140, 21);

		this.add(configLink(entity), 433, 88);

		this.add(connectLink(entity), 500, 88);

		this.add(friendsLink(entity), 10, 136);

		this.add(vpEntitiesRelated, 10, 190);

		this.add(vpMiddleContent, 185, 159);
		vpMiddleContent.setSize("100px", "100px");

		vpEntitiesRelated.clear();
		EntitiesList entitiesList = new EntitiesList(
				entity.getEntitiesRelated());
		vpEntitiesRelated.add(entitiesList);

		VerticalPanel verticalPanel = new VerticalPanel();
		this.add(verticalPanel, 10, 235);
		verticalPanel.setSize("119px", "24px");

	}

	private Anchor configLink(final Entity entity) {

		Anchor anchorConfig = new Anchor("Config");

		anchorConfig.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {

				vpMiddleContent.clear();
				vpMiddleContent.add(new EditEntity(entity));
			}
		});

		return anchorConfig;
	}

	private Anchor connectLink(final Entity entity) {

		Anchor anchorConfig = new Anchor("Connect");

		anchorConfig.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {

				vpMiddleContent.clear();
				vpMiddleContent.add(new ConnectEntityForm(entity));
			}
		});

		return anchorConfig;
	}

	private Anchor friendsLink(final Entity entity) {

		Anchor anchorFriends = new Anchor("FRIENDS");

		anchorFriends.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {

				vpMiddleContent.clear();
				vpMiddleContent.add(new FriendsPanel(entity));
			}
		});

		return anchorFriends;
	}
}
